using System.Data;
using System.Linq;

namespace MDSAdministrationTest
{
    public static class DataTableSchemaCompare
    {
        public static bool SchemaNameOnlyEquals(this DataTable dt, DataTable value)
        {
            if (dt.Columns.Count != value.Columns.Count)
                return false;

            var dtColumns = dt.Columns.Cast<DataColumn>();
            var valueColumns = value.Columns.Cast<DataColumn>();

            foreach (var col in dtColumns)
            {

                if (!value.Columns.Contains(col.ColumnName))
                {   
                    return false;
                }

            }

            return true;

        }

        public static bool SchemaEquals(this DataTable dt, DataTable value)
        {
            if (dt.Columns.Count != value.Columns.Count)
                return false;

            var dtColumns = dt.Columns.Cast<DataColumn>();
            var valueColumns = value.Columns.Cast<DataColumn>();

            var exceptCount = dtColumns.Except(valueColumns, DataColumnEqualityComparer.Instance).Count();
            return (exceptCount == 0);
        }
    }
}